package com.pikaqiu.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.pikaqiu.api.UserClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HelloService implements UserClient {

    @Autowired
    RestTemplate restTemplate;

    //对该方法创建了熔断器的功能
    @HystrixCommand(fallbackMethod = "hiError")
    public String hiService(String name)  {
        return restTemplate.getForObject("http://SERVICE-RIBBON/hello?name="+name,String.class);
    }


    /*调不通就会走这个方法*/
    public String hiError(String name) {
        return "hi,"+name+",sorry,error!";
    }

    @Override
    public String getUserInfo() {
        System.out.println("----错误-----");
        return null;
    }

    @Override
    public String hi(String name) {
        System.out.println("错误------------" + name);
        return name;
    }
}